﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Strategy.Core.TradeTypes;

namespace Strategy.Core.TradeStreams.Indicators
{
    public class SMAIndicatorStream : AIndicator
    {
        public static string generateID(long p) { return "SMA " + p; }
        public long Period { get; protected set; } 

        protected CandleStream candleStream = null;
        private SMAIndicatorStream()
        {
        }
        public SMAIndicatorStream(CandleStream candle,long period)
        {
            values = new List<IndicatorValue>();
            candleStream = candle;
            Interval = candle.Interval;
            Period = period;
        }

        

        public override int getLevel()
        {
            return 1;
        }

        public override string getID()
        {
            return generateID(Period);
        }

        protected override double getCalculatedValue(QuoteData qd)
        {
            double avsum = 0;
            for (int i = 0; i < candleStream.Count; ++i)
                avsum += candleStream.getByIndexFromStart(i).Close;
            avsum /= candleStream.Count;
            return avsum;
        }
    }
}
